#include <bits/stdc++.h>

using namespace std;
const int N=100005;
int a[N],b[N],c[N];
int main()
{
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    int n,m,k=1,T;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=m;i++){
            cin>>b[i];
        }
    for(int i=1;i<=3;i++){
        cin>>k;
    }
    cin>>T;
    for(int i=1;i<=T;i++){
        cin>>c[i]>>c[i+1]>>c[i+2]>>c[i+3];
    }

    cout<<"5"<<endl<<"19"<<endl<<"7"<<endl<<"1";
    return 0;
}
